package com.bw.shopping.bind;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import androidx.databinding.BindingAdapter;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bw.my.mvvm.view.ShipAddressActivity;
import com.bw.shopping.R;
import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.HashMap;
import java.util.List;

public class PrderFormBind {

    @BindingAdapter(value = {"adapter","consignee","distribution"})
    public static void confirm(RecyclerView recyclerView,
                               BaseQuickAdapter adapter,
                               String consignee,
                               String[] distribution){
        LinearLayoutManager manager = new LinearLayoutManager(recyclerView.getContext());
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        View header = LayoutInflater.from(recyclerView.getContext()).inflate(R.layout.item_consignee,null);
        TextView consign = header.findViewById(R.id.item_consignee);
        consign.setText(consignee);
        consign.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(recyclerView.getContext(), ShipAddressActivity.class);
                recyclerView.getContext().startActivity(intent);
            }
        });
        adapter.addHeaderView(header);
        View footer = LayoutInflater.from(recyclerView.getContext()).inflate(R.layout.item_distribution,null);
        TextView distribution1 = footer.findViewById(R.id.item_distribution1);
        TextView distribution2 = footer.findViewById(R.id.item_distribution2);
        distribution1.setText(distribution[0]);
        distribution2.setText(distribution[1]);
        adapter.addFooterView(footer);
        recyclerView.setLayoutManager(manager);
        recyclerView.setAdapter(adapter);
    }
}
